<?php
global $AppUI, $m, $tab;

$perms =& $AppUI->acl();

require_once($AppUI->getModuleClass('companies'));
require_once($AppUI->getModuleClass('suppliers'));
require_once($AppUI->getModuleClass('items'));
require_once($AppUI->getModuleClass('quotations'));
require_once($AppUI->getMasterDataClass('mdtype'));
require_once($AppUI->getMasterDataClass('mdstatus'));
require_once($AppUI->getMasterDataClass('mdcurrency'));
require_once($AppUI->getMasterDataClass('mddivision'));
require_once($AppUI->getMasterDataClass('mdcostcenter'));
require_once($AppUI->getMasterDataClass('mdunit'));
require_once(DP_BASE_DIR."/modules/masterdata/classification/classification.class.php");

$arrCargo = getTypeList('CargoType', true);
$arrContainer = getTypeList('Container', false);
$arrMethod = getTypeList('Method', false);
$arrShipType = getTypeList('ShippingType', false, true);
$arrQuotationType = getTypeList('Quotation', true);
$arrQuotationStatus = getStatusList('Quotation', false);
$arrProjectStatus = getStatusList('Reference', true);
$arrProjectType = getTypeList('Reference', true);
$arrUnit = getUnitList(null, false);
$arrExpenseTypes = dPgetSysVal('TaskLogExpense');
$arrSuppliers = getSupplierList(false);
$arrClassifications = getClassificationList(false);
$arrCompanyTypes = getTypeList('Customer', false);
$arrCompanyStatuses = getStatusList('Customer', false);
$arrSupplierTypes = getTypeList('Supplier', false);
$arrSupplierStatuses = getStatusList('Supplier', false);
$arrDivisions = getDivisionList(false);
$arrCostcenters = getCostCenterList(false);
$arrResources = getUsersArray();

$arrVATTypes = array(0 => '',
					1 => 'Including',
					2 => 'Excluding');
//$arrUQuantity = getUnitList('Quantity', TRUE);
//$arrUVolume = getUnitList('Volume', TRUE);
//$arrUWeight = getUnitList('Weight', TRUE);
$arrCurrency = getCurrencyList();

$q = new DBQuery();
$q->addTable('companies');
$q->addQuery('company_id, company_name, company_code');
$q->addOrder('company_name');
$arrCustomer = $q->loadList();

$obj = new CItem();
$arrItem = $obj->getItemsList4AutoCompleter();

$q = new DBQuery();
$q->addTable('users', 'u');
$q->addTable('contacts', 'c');
//$q->addTable('project_contacts', 'pc');
$q->addQuery('user_id, concat(contact_first_name, \' \', contact_last_name) as contact_name');
//$q->addWhere('pc.contact_id = u.user_id AND u.user_contact = c.contact_id AND pc.project_id = '.$task_project);
$q->addWhere('u.user_contact = c.contact_id');
$q->addOrder('contact_first_name');
$sql = $q->prepare();
$arrUsers = db_loadHashList($sql);

header('Content-Type: text/xml');

$xml = new XmlWriter();
$xml->openMemory();
$xml->startDocument('1.0', 'UTF-8');
$xml->startElement('masterdata');

obj2xml($xml, 'items', 'item', $arrItem, 'id', 'name');
obj2xml($xml, 'customers', 'type', $arrCustomer, 'company_id', 'company_name');
obj2xml($xml, 'shippingTypes', 'type', $arrShipType, 'type_id', 'name');

array2xml($xml, 'users', 'type', $arrUsers);
array2xml($xml, 'quotationTypes', 'type', $arrQuotationType);
array2xml($xml, 'quotationStatuses', 'type', $arrQuotationStatus);
array2xml($xml, 'cargoTypes', 'type', $arrCargo);
array2xml($xml, 'containers', 'type', $arrContainer);
array2xml($xml, 'methods', 'type', $arrMethod);
array2xml($xml, 'companyTypes', 'type', $arrCompanyTypes);
array2xml($xml, 'companyStatuses', 'type', $arrCompanyStatuses);
array2xml($xml, 'currencies', 'type', $arrCurrency);
array2xml($xml, 'units', 'type', $arrUnit);
array2xml($xml, 'vatTypes', 'type', $arrVATTypes);
array2xml($xml, 'expenseTypes', 'type', $arrExpenseTypes);
array2xml($xml, 'projectTypes', 'type', $arrProjectType);
array2xml($xml, 'projectStatuses', 'type', $arrProjectStatus);
array2xml($xml, 'suppliers', 'type', $arrSuppliers);
array2xml($xml, 'classifications', 'type', $arrClassifications);
array2xml($xml, 'supplierTypes', 'type', $arrSupplierTypes);
array2xml($xml, 'supplierStatuses', 'type', $arrSupplierStatuses);
array2xml($xml, 'divisions', 'type', $arrDivisions);
array2xml($xml, 'costcenters', 'type', $arrCostcenters);

//$xml->startElement('units');
//array2xml($xml, 'quantity', 'unit', $arrUQuantity);
//array2xml($xml, 'volume', 'unit', $arrUVolume);
//array2xml($xml, 'weight', 'unit', $arrUWeight);
//
//$xml->endElement();

$xml->endElement();
echo $xml->outputMemory(true);
?>
